<?php
session_start();
require($_SERVER['DOCUMENT_ROOT'].'/resources/lib/database.php');
require($_SERVER['DOCUMENT_ROOT'].'/resources/lib/functions.php');
require($_SERVER['DOCUMENT_ROOT'].'/resources/lib/class.admin.php');
$admin = new admin();
$admin->canView($_SERVER['PHP_SELF']);
ob_start("sanitize_output"); 
$mods=$admin->getModules();

?>
<div class="oneem" style="height:90%;">
<div class="qt-tab-wrapper" style="height:90%;">
<ul class="qt">
<li><a href="#t1-pages" id="tt1" class="qta">Modules</a></li>
</ul>
<div id="t1-pages" class="qt-content-container" style="display:none;">
	<div style="width:50%;float:left;">
    	<h2 class="form-heading">Install a new module</h2>
    <form target="upload_module" method="post" action="/admin/resources/php/requests/actions/upload_module.php" enctype="multipart/form-data">
    	<input type="file" name="module" id="module" /><br /><br /><input type="submit" class="button" value="Install module" />
    </form>
        <iframe style="display:none;" name="upload_module" id="upload_module"></iframe>
    
    
    </div>
    <div style="width:48%;float:right;">
    
<form class="inline" action="/admin/resources/php/requests/actions/save-modules.php">
	<input type="submit" class="button" value="Save changes" style="float:right;margin-right:8px;" />
    <h2 class="form-heading">Installed modules</h2>
<input type="hidden" class="settings" value='{"buttonWaitingValue":"Saving","updateNode":"#response"}' />	
        <table width="99%" class="headed-table">
	<thead>
    <tr valign="top">
    <td width="1%" class="hleft"></td>
    <td width="25%"><h6>&nbsp;Name</h6></td>
	<td width="10%"><h6>&nbsp;Version</h6></td>
    <td width="34%"><h6>&nbsp;Build Date</h6></td>
    <td width="5%" class="hright"><h6>&nbsp;Active</h6></td>
</tr>
</thead>
<tbody>
<?php 
foreach($mods['results'] as $row) {
	$bg=($i%2) ? 'odd' : '';
	$active=($row['active']==1) ? 'Yes' : 'No';
	echo('<tr>');
	echo('<td class="left '.$bg.'" width="1%"><a href="/admin/resources/php/requests/actions/delete-module.php?id='.(string)$row['_id'].'" class="delete-module tip" title="Delete this module"><img src="/admin/resources/images/cancel.png" /></a></td>');
	echo('<td class="'.($bg).'" width="25%">'.$row['name'].'</td>');
	echo('<td class="'.$bg.'" width="10%">'.$row['version'].'</td>');
	echo('<td class="'.$bg.'" width="34%">'.$row['build_date'].'</td>');
	echo('<td class="right '.$bg.'" width="5%"><select class="form-field" style="width:56px;" name="module_active['.(string)$row['_id'].']">'.$admin->selectYesNo($row['active']).'</select></td>');

	echo('</tr>');
	$i++;
}
unset($row);
?>


</tbody>
</table> 
</form> 
<br />      
    </div>

</div>
</div>
</div>
<script>$("#tt1").click();</script>